package com.tedu.spring.boot.demo1.controller;

import com.tedu.spring.boot.demo1.common.JSONResult;
import com.tedu.spring.boot.demo1.entity.dto.UserLoginDTO;
import com.tedu.spring.boot.demo1.entity.dto.UserRegDTO;
import com.tedu.spring.boot.demo1.entity.vo.UserVO;
import com.tedu.spring.boot.demo1.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author：毕龙
 * Date: 2024/8/27 14:50
 * @RestController  响应的数据类型是一个json字符串
 * @RequestMapping  请求的一级路径
 * @CrossOrigin  解决跨域请求的问题
 */
@RestController
@RequestMapping("/v1/users/")
@Slf4j
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("reg")
    public JSONResult register(@RequestBody UserRegDTO userRegDTO){
        log.debug("接收请求的参数：{}", userRegDTO);
        userService.insertUser(userRegDTO);
        return JSONResult.ok();
    }


    @PostMapping("login")
    public JSONResult login(@RequestBody UserLoginDTO userLoginDTO){
        log.debug("接收请求的参数：{}", userLoginDTO);
        UserVO userVO = userService.selectUser(userLoginDTO);
        return JSONResult.ok(userVO);
    }


}
